<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>gauge.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_gauge.js.html">gauge.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>
<a name="line16"></a>/**
<a name="line17"></a> * @fileoverview Gauge UI component, using browser vector graphics.
<a name="line18"></a> * @see ../demos/gauge.html
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.ui.Gauge&#39;);
<a name="line23"></a>goog.provide(&#39;goog.ui.GaugeColoredRange&#39;);
<a name="line24"></a>
<a name="line25"></a>
<a name="line26"></a>goog.require(&#39;goog.a11y.aria&#39;);
<a name="line27"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line28"></a>goog.require(&#39;goog.events&#39;);
<a name="line29"></a>goog.require(&#39;goog.fx.Animation&#39;);
<a name="line30"></a>goog.require(&#39;goog.fx.Transition&#39;);
<a name="line31"></a>goog.require(&#39;goog.fx.easing&#39;);
<a name="line32"></a>goog.require(&#39;goog.graphics&#39;);
<a name="line33"></a>goog.require(&#39;goog.graphics.Font&#39;);
<a name="line34"></a>goog.require(&#39;goog.graphics.Path&#39;);
<a name="line35"></a>goog.require(&#39;goog.graphics.SolidFill&#39;);
<a name="line36"></a>goog.require(&#39;goog.math&#39;);
<a name="line37"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line38"></a>goog.require(&#39;goog.ui.GaugeTheme&#39;);
<a name="line39"></a>
<a name="line40"></a>
<a name="line41"></a>
<a name="line42"></a>/**
<a name="line43"></a> * Information on how to decorate a range in the gauge.
<a name="line44"></a> * This is an internal-only class.
<a name="line45"></a> * @param {number} fromValue The range start (minimal) value.
<a name="line46"></a> * @param {number} toValue The range end (maximal) value.
<a name="line47"></a> * @param {string} backgroundColor Color to fill the range background with.
<a name="line48"></a> * @constructor
<a name="line49"></a> * @final
<a name="line50"></a> */
<a name="line51"></a>goog.ui.GaugeColoredRange = function(fromValue, toValue, backgroundColor) {
<a name="line52"></a>
<a name="line53"></a>  /**
<a name="line54"></a>   * The range start (minimal) value.
<a name="line55"></a>   * @type {number}
<a name="line56"></a>   */
<a name="line57"></a>  this.fromValue = fromValue;
<a name="line58"></a>
<a name="line59"></a>
<a name="line60"></a>  /**
<a name="line61"></a>   * The range end (maximal) value.
<a name="line62"></a>   * @type {number}
<a name="line63"></a>   */
<a name="line64"></a>  this.toValue = toValue;
<a name="line65"></a>
<a name="line66"></a>
<a name="line67"></a>  /**
<a name="line68"></a>   * Color to fill the range background with.
<a name="line69"></a>   * @type {string}
<a name="line70"></a>   */
<a name="line71"></a>  this.backgroundColor = backgroundColor;
<a name="line72"></a>};
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>
<a name="line76"></a>/**
<a name="line77"></a> * A UI component that displays a gauge.
<a name="line78"></a> * A gauge displayes a current value within a round axis that represents a
<a name="line79"></a> * given range.
<a name="line80"></a> * The gauge is built from an external border, and internal border inside it,
<a name="line81"></a> * ticks and labels inside the internal border, and a needle that points to
<a name="line82"></a> * the current value.
<a name="line83"></a> * @param {number} width The width in pixels.
<a name="line84"></a> * @param {number} height The height in pixels.
<a name="line85"></a> * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper object for the
<a name="line86"></a> *     document we want to render in.
<a name="line87"></a> * @constructor
<a name="line88"></a> * @extends {goog.ui.Component}
<a name="line89"></a> * @final
<a name="line90"></a> */
<a name="line91"></a>goog.ui.Gauge = function(width, height, opt_domHelper) {
<a name="line92"></a>  goog.ui.Component.call(this, opt_domHelper);
<a name="line93"></a>
<a name="line94"></a>  /**
<a name="line95"></a>   * The width in pixels of this component.
<a name="line96"></a>   * @type {number}
<a name="line97"></a>   * @private
<a name="line98"></a>   */
<a name="line99"></a>  this.width_ = width;
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>  /**
<a name="line103"></a>   * The height in pixels of this component.
<a name="line104"></a>   * @type {number}
<a name="line105"></a>   * @private
<a name="line106"></a>   */
<a name="line107"></a>  this.height_ = height;
<a name="line108"></a>
<a name="line109"></a>
<a name="line110"></a>  /**
<a name="line111"></a>   * The underlying graphics.
<a name="line112"></a>   * @type {goog.graphics.AbstractGraphics}
<a name="line113"></a>   * @private
<a name="line114"></a>   */
<a name="line115"></a>  this.graphics_ = goog.graphics.createGraphics(width, height,
<a name="line116"></a>      null, null, opt_domHelper);
<a name="line117"></a>
<a name="line118"></a>
<a name="line119"></a>  /**
<a name="line120"></a>   * Colors to paint the background of certain ranges (optional).
<a name="line121"></a>   * @type {Array.&lt;goog.ui.GaugeColoredRange&gt;}
<a name="line122"></a>   * @private
<a name="line123"></a>   */
<a name="line124"></a>  this.rangeColors_ = [];
<a name="line125"></a>};
<a name="line126"></a>goog.inherits(goog.ui.Gauge, goog.ui.Component);
<a name="line127"></a>
<a name="line128"></a>
<a name="line129"></a>/**
<a name="line130"></a> * Constant for a background color for a gauge area.
<a name="line131"></a> */
<a name="line132"></a>goog.ui.Gauge.RED = &#39;#ffc0c0&#39;;
<a name="line133"></a>
<a name="line134"></a>
<a name="line135"></a>/**
<a name="line136"></a> * Constant for a background color for a gauge area.
<a name="line137"></a> */
<a name="line138"></a>goog.ui.Gauge.GREEN = &#39;#c0ffc0&#39;;
<a name="line139"></a>
<a name="line140"></a>
<a name="line141"></a>/**
<a name="line142"></a> * Constant for a background color for a gauge area.
<a name="line143"></a> */
<a name="line144"></a>goog.ui.Gauge.YELLOW = &#39;#ffffa0&#39;;
<a name="line145"></a>
<a name="line146"></a>
<a name="line147"></a>/**
<a name="line148"></a> * The radius of the entire gauge from the canvas size.
<a name="line149"></a> * @type {number}
<a name="line150"></a> */
<a name="line151"></a>goog.ui.Gauge.FACTOR_RADIUS_FROM_SIZE = 0.45;
<a name="line152"></a>
<a name="line153"></a>
<a name="line154"></a>/**
<a name="line155"></a> * The ratio of internal gauge radius from entire radius.
<a name="line156"></a> * The remaining area is the border around the gauge.
<a name="line157"></a> * @type {number}
<a name="line158"></a> */
<a name="line159"></a>goog.ui.Gauge.FACTOR_MAIN_AREA = 0.9;
<a name="line160"></a>
<a name="line161"></a>
<a name="line162"></a>/**
<a name="line163"></a> * The ratio of the colored background area for value ranges.
<a name="line164"></a> * The colored area width is computed as
<a name="line165"></a> * InternalRadius * (1 - FACTOR_COLOR_RADIUS)
<a name="line166"></a> * @type {number}
<a name="line167"></a> */
<a name="line168"></a>goog.ui.Gauge.FACTOR_COLOR_RADIUS = 0.75;
<a name="line169"></a>
<a name="line170"></a>
<a name="line171"></a>/**
<a name="line172"></a> * The ratio of the major ticks length start position, from the radius.
<a name="line173"></a> * The major ticks length width is computed as
<a name="line174"></a> * InternalRadius * (1 - FACTOR_MAJOR_TICKS)
<a name="line175"></a> * @type {number}
<a name="line176"></a> */
<a name="line177"></a>goog.ui.Gauge.FACTOR_MAJOR_TICKS = 0.8;
<a name="line178"></a>
<a name="line179"></a>
<a name="line180"></a>/**
<a name="line181"></a> * The ratio of the minor ticks length start position, from the radius.
<a name="line182"></a> * The minor ticks length width is computed as
<a name="line183"></a> * InternalRadius * (1 - FACTOR_MINOR_TICKS)
<a name="line184"></a> * @type {number}
<a name="line185"></a> */
<a name="line186"></a>goog.ui.Gauge.FACTOR_MINOR_TICKS = 0.9;
<a name="line187"></a>
<a name="line188"></a>
<a name="line189"></a>/**
<a name="line190"></a> * The length of the needle front (value facing) from the internal radius.
<a name="line191"></a> * The needle front is the part of the needle that points to the value.
<a name="line192"></a> * @type {number}
<a name="line193"></a> */
<a name="line194"></a>goog.ui.Gauge.FACTOR_NEEDLE_FRONT = 0.95;
<a name="line195"></a>
<a name="line196"></a>
<a name="line197"></a>/**
<a name="line198"></a> * The length of the needle back relative to the internal radius.
<a name="line199"></a> * The needle back is the part of the needle that points away from the value.
<a name="line200"></a> * @type {number}
<a name="line201"></a> */
<a name="line202"></a>goog.ui.Gauge.FACTOR_NEEDLE_BACK = 0.3;
<a name="line203"></a>
<a name="line204"></a>
<a name="line205"></a>/**
<a name="line206"></a> * The width of the needle front at the hinge.
<a name="line207"></a> * This is the width of the curve control point, the actual width is
<a name="line208"></a> * computed by the curve itself.
<a name="line209"></a> * @type {number}
<a name="line210"></a> */
<a name="line211"></a>goog.ui.Gauge.FACTOR_NEEDLE_WIDTH = 0.07;
<a name="line212"></a>
<a name="line213"></a>
<a name="line214"></a>/**
<a name="line215"></a> * The width (radius) of the needle hinge from the gauge radius.
<a name="line216"></a> * @type {number}
<a name="line217"></a> */
<a name="line218"></a>goog.ui.Gauge.FACTOR_NEEDLE_HINGE = 0.15;
<a name="line219"></a>
<a name="line220"></a>
<a name="line221"></a>/**
<a name="line222"></a> * The title font size (height) for titles relative to the internal radius.
<a name="line223"></a> * @type {number}
<a name="line224"></a> */
<a name="line225"></a>goog.ui.Gauge.FACTOR_TITLE_FONT_SIZE = 0.16;
<a name="line226"></a>
<a name="line227"></a>
<a name="line228"></a>/**
<a name="line229"></a> * The offset of the title from the center, relative to the internal radius.
<a name="line230"></a> * @type {number}
<a name="line231"></a> */
<a name="line232"></a>goog.ui.Gauge.FACTOR_TITLE_OFFSET = 0.35;
<a name="line233"></a>
<a name="line234"></a>
<a name="line235"></a>/**
<a name="line236"></a> * The formatted value font size (height) relative to the internal radius.
<a name="line237"></a> * @type {number}
<a name="line238"></a> */
<a name="line239"></a>goog.ui.Gauge.FACTOR_VALUE_FONT_SIZE = 0.18;
<a name="line240"></a>
<a name="line241"></a>
<a name="line242"></a>/**
<a name="line243"></a> * The title font size (height) for tick labels relative to the internal radius.
<a name="line244"></a> * @type {number}
<a name="line245"></a> */
<a name="line246"></a>goog.ui.Gauge.FACTOR_TICK_LABEL_FONT_SIZE = 0.14;
<a name="line247"></a>
<a name="line248"></a>
<a name="line249"></a>/**
<a name="line250"></a> * The offset of the formatted value down from the center, relative to the
<a name="line251"></a> * internal radius.
<a name="line252"></a> * @type {number}
<a name="line253"></a> */
<a name="line254"></a>goog.ui.Gauge.FACTOR_VALUE_OFFSET = 0.75;
<a name="line255"></a>
<a name="line256"></a>
<a name="line257"></a>/**
<a name="line258"></a> * The font name for title text.
<a name="line259"></a> * @type {string}
<a name="line260"></a> */
<a name="line261"></a>goog.ui.Gauge.TITLE_FONT_NAME = &#39;arial&#39;;
<a name="line262"></a>
<a name="line263"></a>
<a name="line264"></a>/**
<a name="line265"></a> * The maximal size of a step the needle can move (percent from size of range).
<a name="line266"></a> * If the needle needs to move more, it will be moved in animated steps, to
<a name="line267"></a> * show a smooth transition between values.
<a name="line268"></a> * @type {number}
<a name="line269"></a> */
<a name="line270"></a>goog.ui.Gauge.NEEDLE_MOVE_MAX_STEP = 0.02;
<a name="line271"></a>
<a name="line272"></a>
<a name="line273"></a>/**
<a name="line274"></a> * Time in miliseconds for animating a move of the value pointer.
<a name="line275"></a> * @type {number}
<a name="line276"></a> */
<a name="line277"></a>goog.ui.Gauge.NEEDLE_MOVE_TIME = 400;
<a name="line278"></a>
<a name="line279"></a>
<a name="line280"></a>/**
<a name="line281"></a> * Tolerance factor for how much values can exceed the range (being too
<a name="line282"></a> * low or too high). The value is presented as a position (percentage).
<a name="line283"></a> * @type {number}
<a name="line284"></a> */
<a name="line285"></a>goog.ui.Gauge.MAX_EXCEED_POSITION_POSITION = 0.02;
<a name="line286"></a>
<a name="line287"></a>
<a name="line288"></a>/**
<a name="line289"></a> * The minimal value that can be displayed.
<a name="line290"></a> * @private
<a name="line291"></a> * @type {number}
<a name="line292"></a> */
<a name="line293"></a>goog.ui.Gauge.prototype.minValue_ = 0;
<a name="line294"></a>
<a name="line295"></a>
<a name="line296"></a>/**
<a name="line297"></a> * The maximal value that can be displayed.
<a name="line298"></a> * @private
<a name="line299"></a> * @type {number}
<a name="line300"></a> */
<a name="line301"></a>goog.ui.Gauge.prototype.maxValue_ = 100;
<a name="line302"></a>
<a name="line303"></a>
<a name="line304"></a>/**
<a name="line305"></a> * The number of major tick sections.
<a name="line306"></a> * @private
<a name="line307"></a> * @type {number}
<a name="line308"></a> */
<a name="line309"></a>goog.ui.Gauge.prototype.majorTicks_ = 5;
<a name="line310"></a>
<a name="line311"></a>
<a name="line312"></a>/**
<a name="line313"></a> * The number of minor tick sections in each major tick section.
<a name="line314"></a> * @private
<a name="line315"></a> * @type {number}
<a name="line316"></a> */
<a name="line317"></a>goog.ui.Gauge.prototype.minorTicks_ = 2;
<a name="line318"></a>
<a name="line319"></a>
<a name="line320"></a>/**
<a name="line321"></a> * The current value that needs to be displayed in the gauge.
<a name="line322"></a> * @private
<a name="line323"></a> * @type {number}
<a name="line324"></a> */
<a name="line325"></a>goog.ui.Gauge.prototype.value_ = 0;
<a name="line326"></a>
<a name="line327"></a>
<a name="line328"></a>/**
<a name="line329"></a> * The current value formatted into a String.
<a name="line330"></a> * @private
<a name="line331"></a> * @type {?string}
<a name="line332"></a> */
<a name="line333"></a>goog.ui.Gauge.prototype.formattedValue_ = null;
<a name="line334"></a>
<a name="line335"></a>
<a name="line336"></a>/**
<a name="line337"></a> * The current colors theme.
<a name="line338"></a> * @private
<a name="line339"></a> * @type {goog.ui.GaugeTheme?}
<a name="line340"></a> */
<a name="line341"></a>goog.ui.Gauge.prototype.theme_ = null;
<a name="line342"></a>
<a name="line343"></a>
<a name="line344"></a>/**
<a name="line345"></a> * Title to display above the gauge center.
<a name="line346"></a> * @private
<a name="line347"></a> * @type {?string}
<a name="line348"></a> */
<a name="line349"></a>goog.ui.Gauge.prototype.titleTop_ = null;
<a name="line350"></a>
<a name="line351"></a>
<a name="line352"></a>/**
<a name="line353"></a> * Title to display below the gauge center.
<a name="line354"></a> * @private
<a name="line355"></a> * @type {?string}
<a name="line356"></a> */
<a name="line357"></a>goog.ui.Gauge.prototype.titleBottom_ = null;
<a name="line358"></a>
<a name="line359"></a>
<a name="line360"></a>/**
<a name="line361"></a> * Font to use for drawing titles.
<a name="line362"></a> * If null (default), computed dynamically with a size relative to the
<a name="line363"></a> * gauge radius.
<a name="line364"></a> * @private
<a name="line365"></a> * @type {goog.graphics.Font?}
<a name="line366"></a> */
<a name="line367"></a>goog.ui.Gauge.prototype.titleFont_ = null;
<a name="line368"></a>
<a name="line369"></a>
<a name="line370"></a>/**
<a name="line371"></a> * Font to use for drawing the formatted value.
<a name="line372"></a> * If null (default), computed dynamically with a size relative to the
<a name="line373"></a> * gauge radius.
<a name="line374"></a> * @private
<a name="line375"></a> * @type {goog.graphics.Font?}
<a name="line376"></a> */
<a name="line377"></a>goog.ui.Gauge.prototype.valueFont_ = null;
<a name="line378"></a>
<a name="line379"></a>
<a name="line380"></a>/**
<a name="line381"></a> * Font to use for drawing tick labels.
<a name="line382"></a> * If null (default), computed dynamically with a size relative to the
<a name="line383"></a> * gauge radius.
<a name="line384"></a> * @private
<a name="line385"></a> * @type {goog.graphics.Font?}
<a name="line386"></a> */
<a name="line387"></a>goog.ui.Gauge.prototype.tickLabelFont_ = null;
<a name="line388"></a>
<a name="line389"></a>
<a name="line390"></a>/**
<a name="line391"></a> * The size in angles of the gauge axis area.
<a name="line392"></a> * @private
<a name="line393"></a> * @type {number}
<a name="line394"></a> */
<a name="line395"></a>goog.ui.Gauge.prototype.angleSpan_ = 270;
<a name="line396"></a>
<a name="line397"></a>
<a name="line398"></a>/**
<a name="line399"></a> * The radius for drawing the needle.
<a name="line400"></a> * Computed on full redraw, and used on every animation step of moving
<a name="line401"></a> * the needle.
<a name="line402"></a> * @type {number}
<a name="line403"></a> * @private
<a name="line404"></a> */
<a name="line405"></a>goog.ui.Gauge.prototype.needleRadius_ = 0;
<a name="line406"></a>
<a name="line407"></a>
<a name="line408"></a>/**
<a name="line409"></a> * The group elemnt of the needle. Contains all elements that change when the
<a name="line410"></a> * gauge value changes.
<a name="line411"></a> * @type {goog.graphics.GroupElement?}
<a name="line412"></a> * @private
<a name="line413"></a> */
<a name="line414"></a>goog.ui.Gauge.prototype.needleGroup_ = null;
<a name="line415"></a>
<a name="line416"></a>
<a name="line417"></a>/**
<a name="line418"></a> * The current position (0-1) of the visible needle.
<a name="line419"></a> * Initially set to null to prevent animation on first opening of the gauge.
<a name="line420"></a> * @type {?number}
<a name="line421"></a> * @private
<a name="line422"></a> */
<a name="line423"></a>goog.ui.Gauge.prototype.needleValuePosition_ = null;
<a name="line424"></a>
<a name="line425"></a>
<a name="line426"></a>/**
<a name="line427"></a> * Text labels to display by major tick marks.
<a name="line428"></a> * @type {Array.&lt;string&gt;?}
<a name="line429"></a> * @private
<a name="line430"></a> */
<a name="line431"></a>goog.ui.Gauge.prototype.majorTickLabels_ = null;
<a name="line432"></a>
<a name="line433"></a>
<a name="line434"></a>/**
<a name="line435"></a> * Animation object while needle is being moved (animated).
<a name="line436"></a> * @type {goog.fx.Animation?}
<a name="line437"></a> * @private
<a name="line438"></a> */
<a name="line439"></a>goog.ui.Gauge.prototype.animation_ = null;
<a name="line440"></a>
<a name="line441"></a>
<a name="line442"></a>/**
<a name="line443"></a> * @return {number} The minimum value of the range.
<a name="line444"></a> */
<a name="line445"></a>goog.ui.Gauge.prototype.getMinimum = function() {
<a name="line446"></a>  return this.minValue_;
<a name="line447"></a>};
<a name="line448"></a>
<a name="line449"></a>
<a name="line450"></a>/**
<a name="line451"></a> * Sets the minimum value of the range
<a name="line452"></a> * @param {number} min The minimum value of the range.
<a name="line453"></a> */
<a name="line454"></a>goog.ui.Gauge.prototype.setMinimum = function(min) {
<a name="line455"></a>  this.minValue_ = min;
<a name="line456"></a>  var element = this.getElement();
<a name="line457"></a>  if (element) {
<a name="line458"></a>    goog.a11y.aria.setState(element, &#39;valuemin&#39;, min);
<a name="line459"></a>  }
<a name="line460"></a>};
<a name="line461"></a>
<a name="line462"></a>
<a name="line463"></a>/**
<a name="line464"></a> * @return {number} The maximum value of the range.
<a name="line465"></a> */
<a name="line466"></a>goog.ui.Gauge.prototype.getMaximum = function() {
<a name="line467"></a>  return this.maxValue_;
<a name="line468"></a>};
<a name="line469"></a>
<a name="line470"></a>
<a name="line471"></a>/**
<a name="line472"></a> * Sets the maximum number of the range
<a name="line473"></a> * @param {number} max The maximum value of the range.
<a name="line474"></a> */
<a name="line475"></a>goog.ui.Gauge.prototype.setMaximum = function(max) {
<a name="line476"></a>  this.maxValue_ = max;
<a name="line477"></a>
<a name="line478"></a>  var element = this.getElement();
<a name="line479"></a>  if (element) {
<a name="line480"></a>    goog.a11y.aria.setState(element, &#39;valuemax&#39;, max);
<a name="line481"></a>  }
<a name="line482"></a>};
<a name="line483"></a>
<a name="line484"></a>
<a name="line485"></a>/**
<a name="line486"></a> * Sets the current value range displayed by the gauge.
<a name="line487"></a> * @param {number} value The current value for the gauge. This value
<a name="line488"></a> *     determines the position of the needle of the gauge.
<a name="line489"></a> * @param {string=} opt_formattedValue The string value to show in the gauge.
<a name="line490"></a> *     If not specified, no string value will be displayed.
<a name="line491"></a> */
<a name="line492"></a>goog.ui.Gauge.prototype.setValue = function(value, opt_formattedValue) {
<a name="line493"></a>  this.value_ = value;
<a name="line494"></a>  this.formattedValue_ = opt_formattedValue || null;
<a name="line495"></a>
<a name="line496"></a>  this.stopAnimation_(); // Stop the active animation if exists
<a name="line497"></a>
<a name="line498"></a>  // Compute desired value position (normalize value to range 0-1)
<a name="line499"></a>  var valuePosition = this.valueToRangePosition_(value);
<a name="line500"></a>  if (this.needleValuePosition_ == null) {
<a name="line501"></a>    // No animation on initial display
<a name="line502"></a>    this.needleValuePosition_ = valuePosition;
<a name="line503"></a>    this.drawValue_();
<a name="line504"></a>  } else {
<a name="line505"></a>    // Animate move
<a name="line506"></a>    this.animation_ = new goog.fx.Animation([this.needleValuePosition_],
<a name="line507"></a>        [valuePosition],
<a name="line508"></a>        goog.ui.Gauge.NEEDLE_MOVE_TIME,
<a name="line509"></a>        goog.fx.easing.inAndOut);
<a name="line510"></a>
<a name="line511"></a>    var events = [goog.fx.Transition.EventType.BEGIN,
<a name="line512"></a>                  goog.fx.Animation.EventType.ANIMATE,
<a name="line513"></a>                  goog.fx.Transition.EventType.END];
<a name="line514"></a>    goog.events.listen(this.animation_, events, this.onAnimate_, false, this);
<a name="line515"></a>    goog.events.listen(this.animation_, goog.fx.Transition.EventType.END,
<a name="line516"></a>        this.onAnimateEnd_, false, this);
<a name="line517"></a>
<a name="line518"></a>    // Start animation
<a name="line519"></a>    this.animation_.play(false);
<a name="line520"></a>  }
<a name="line521"></a>
<a name="line522"></a>  var element = this.getElement();
<a name="line523"></a>  if (element) {
<a name="line524"></a>    goog.a11y.aria.setState(element, &#39;valuenow&#39;, this.value_);
<a name="line525"></a>  }
<a name="line526"></a>};
<a name="line527"></a>
<a name="line528"></a>
<a name="line529"></a>/**
<a name="line530"></a> * Sets the number of major tick sections and minor tick sections.
<a name="line531"></a> * @param {number} majorUnits The number of major tick sections.
<a name="line532"></a> * @param {number} minorUnits The number of minor tick sections for each major
<a name="line533"></a> *     tick section.
<a name="line534"></a> */
<a name="line535"></a>goog.ui.Gauge.prototype.setTicks = function(majorUnits, minorUnits) {
<a name="line536"></a>  this.majorTicks_ = Math.max(1, majorUnits);
<a name="line537"></a>  this.minorTicks_ = Math.max(1, minorUnits);
<a name="line538"></a>  this.draw_();
<a name="line539"></a>};
<a name="line540"></a>
<a name="line541"></a>
<a name="line542"></a>/**
<a name="line543"></a> * Sets the labels of the major ticks.
<a name="line544"></a> * @param {Array.&lt;string&gt;} tickLabels A text label for each major tick value.
<a name="line545"></a> */
<a name="line546"></a>goog.ui.Gauge.prototype.setMajorTickLabels = function(tickLabels) {
<a name="line547"></a>  this.majorTickLabels_ = tickLabels;
<a name="line548"></a>  this.draw_();
<a name="line549"></a>};
<a name="line550"></a>
<a name="line551"></a>
<a name="line552"></a>/**
<a name="line553"></a> * Sets the top title of the gauge.
<a name="line554"></a> * The top title is displayed above the center.
<a name="line555"></a> * @param {string} text The top title text.
<a name="line556"></a> */
<a name="line557"></a>goog.ui.Gauge.prototype.setTitleTop = function(text) {
<a name="line558"></a>  this.titleTop_ = text;
<a name="line559"></a>  this.draw_();
<a name="line560"></a>};
<a name="line561"></a>
<a name="line562"></a>
<a name="line563"></a>/**
<a name="line564"></a> * Sets the bottom title of the gauge.
<a name="line565"></a> * The top title is displayed below the center.
<a name="line566"></a> * @param {string} text The bottom title text.
<a name="line567"></a> */
<a name="line568"></a>goog.ui.Gauge.prototype.setTitleBottom = function(text) {
<a name="line569"></a>  this.titleBottom_ = text;
<a name="line570"></a>  this.draw_();
<a name="line571"></a>};
<a name="line572"></a>
<a name="line573"></a>
<a name="line574"></a>/**
<a name="line575"></a> * Sets the font for displaying top and bottom titles.
<a name="line576"></a> * @param {goog.graphics.Font} font The font for titles.
<a name="line577"></a> */
<a name="line578"></a>goog.ui.Gauge.prototype.setTitleFont = function(font) {
<a name="line579"></a>  this.titleFont_ = font;
<a name="line580"></a>  this.draw_();
<a name="line581"></a>};
<a name="line582"></a>
<a name="line583"></a>
<a name="line584"></a>/**
<a name="line585"></a> * Sets the font for displaying the formatted value.
<a name="line586"></a> * @param {goog.graphics.Font} font The font for displaying the value.
<a name="line587"></a> */
<a name="line588"></a>goog.ui.Gauge.prototype.setValueFont = function(font) {
<a name="line589"></a>  this.valueFont_ = font;
<a name="line590"></a>  this.drawValue_();
<a name="line591"></a>};
<a name="line592"></a>
<a name="line593"></a>
<a name="line594"></a>/**
<a name="line595"></a> * Sets the color theme for drawing the gauge.
<a name="line596"></a> * @param {goog.ui.GaugeTheme} theme The color theme to use.
<a name="line597"></a> */
<a name="line598"></a>goog.ui.Gauge.prototype.setTheme = function(theme) {
<a name="line599"></a>  this.theme_ = theme;
<a name="line600"></a>  this.draw_();
<a name="line601"></a>};
<a name="line602"></a>
<a name="line603"></a>
<a name="line604"></a>/**
<a name="line605"></a> * Set the background color for a range of values on the gauge.
<a name="line606"></a> * @param {number} fromValue The lower (start) value of the colored range.
<a name="line607"></a> * @param {number} toValue The higher (end) value of the colored range.
<a name="line608"></a> * @param {string} color The color name to paint the range with. For example
<a name="line609"></a> *     &#39;red&#39;, &#39;#ffcc00&#39; or constants like goog.ui.Gauge.RED.
<a name="line610"></a> */
<a name="line611"></a>goog.ui.Gauge.prototype.addBackgroundColor = function(fromValue, toValue,
<a name="line612"></a>    color) {
<a name="line613"></a>  this.rangeColors_.push(
<a name="line614"></a>      new goog.ui.GaugeColoredRange(fromValue, toValue, color));
<a name="line615"></a>  this.draw_();
<a name="line616"></a>};
<a name="line617"></a>
<a name="line618"></a>
<a name="line619"></a>/**
<a name="line620"></a> * Creates the DOM representation of the graphics area.
<a name="line621"></a> * @override
<a name="line622"></a> */
<a name="line623"></a>goog.ui.Gauge.prototype.createDom = function() {
<a name="line624"></a>  this.setElementInternal(this.getDomHelper().createDom(
<a name="line625"></a>      &#39;div&#39;, goog.getCssName(&#39;goog-gauge&#39;), this.graphics_.getElement()));
<a name="line626"></a>};
<a name="line627"></a>
<a name="line628"></a>
<a name="line629"></a>/**
<a name="line630"></a> * Clears the entire graphics area.
<a name="line631"></a> * @private
<a name="line632"></a> */
<a name="line633"></a>goog.ui.Gauge.prototype.clear_ = function() {
<a name="line634"></a>  this.graphics_.clear();
<a name="line635"></a>  this.needleGroup_ = null;
<a name="line636"></a>};
<a name="line637"></a>
<a name="line638"></a>
<a name="line639"></a>/**
<a name="line640"></a> * Redraw the entire gauge.
<a name="line641"></a> * @private
<a name="line642"></a> */
<a name="line643"></a>goog.ui.Gauge.prototype.draw_ = function() {
<a name="line644"></a>  if (!this.isInDocument()) {
<a name="line645"></a>    return;
<a name="line646"></a>  }
<a name="line647"></a>
<a name="line648"></a>  this.clear_();
<a name="line649"></a>
<a name="line650"></a>  var x, y;
<a name="line651"></a>  var size = Math.min(this.width_, this.height_);
<a name="line652"></a>  var r = Math.round(goog.ui.Gauge.FACTOR_RADIUS_FROM_SIZE * size);
<a name="line653"></a>  var cx = this.width_ / 2;
<a name="line654"></a>  var cy = this.height_ / 2;
<a name="line655"></a>
<a name="line656"></a>  var theme = this.theme_;
<a name="line657"></a>  if (!theme) {
<a name="line658"></a>    // Lazy allocation of default theme, common to all instances
<a name="line659"></a>    theme = goog.ui.Gauge.prototype.theme_ = new goog.ui.GaugeTheme();
<a name="line660"></a>  }
<a name="line661"></a>
<a name="line662"></a>  // Draw main circle frame around gauge
<a name="line663"></a>  var graphics = this.graphics_;
<a name="line664"></a>  var stroke = this.theme_.getExternalBorderStroke();
<a name="line665"></a>  var fill = theme.getExternalBorderFill(cx, cy, r);
<a name="line666"></a>  graphics.drawCircle(cx, cy, r, stroke, fill);
<a name="line667"></a>
<a name="line668"></a>  r -= stroke.getWidth();
<a name="line669"></a>  r = Math.round(r * goog.ui.Gauge.FACTOR_MAIN_AREA);
<a name="line670"></a>  stroke = theme.getInternalBorderStroke();
<a name="line671"></a>  fill = theme.getInternalBorderFill(cx, cy, r);
<a name="line672"></a>  graphics.drawCircle(cx, cy, r, stroke, fill);
<a name="line673"></a>  r -= stroke.getWidth() * 2;
<a name="line674"></a>
<a name="line675"></a>  // Draw Background with external and internal borders
<a name="line676"></a>  var rBackgroundInternal = r * goog.ui.Gauge.FACTOR_COLOR_RADIUS;
<a name="line677"></a>  for (var i = 0; i &lt; this.rangeColors_.length; i++) {
<a name="line678"></a>    var rangeColor = this.rangeColors_[i];
<a name="line679"></a>    var fromValue = rangeColor.fromValue;
<a name="line680"></a>    var toValue = rangeColor.toValue;
<a name="line681"></a>    var path = new goog.graphics.Path();
<a name="line682"></a>    var fromAngle = this.valueToAngle_(fromValue);
<a name="line683"></a>    var toAngle = this.valueToAngle_(toValue);
<a name="line684"></a>    // Move to outer point at &quot;from&quot; angle
<a name="line685"></a>    path.moveTo(
<a name="line686"></a>        cx + goog.math.angleDx(fromAngle, r),
<a name="line687"></a>        cy + goog.math.angleDy(fromAngle, r));
<a name="line688"></a>    // Arc to outer point at &quot;to&quot; angle
<a name="line689"></a>    path.arcTo(r, r, fromAngle, toAngle - fromAngle);
<a name="line690"></a>    // Line to inner point at &quot;to&quot; angle
<a name="line691"></a>    path.lineTo(
<a name="line692"></a>        cx + goog.math.angleDx(toAngle, rBackgroundInternal),
<a name="line693"></a>        cy + goog.math.angleDy(toAngle, rBackgroundInternal));
<a name="line694"></a>    // Arc to inner point at &quot;from&quot; angle
<a name="line695"></a>    path.arcTo(
<a name="line696"></a>        rBackgroundInternal, rBackgroundInternal, toAngle, fromAngle - toAngle);
<a name="line697"></a>    path.close();
<a name="line698"></a>    fill = new goog.graphics.SolidFill(rangeColor.backgroundColor);
<a name="line699"></a>    graphics.drawPath(path, null, fill);
<a name="line700"></a>  }
<a name="line701"></a>
<a name="line702"></a>  // Draw titles
<a name="line703"></a>  if (this.titleTop_ || this.titleBottom_) {
<a name="line704"></a>    var font = this.titleFont_;
<a name="line705"></a>    if (!font) {
<a name="line706"></a>      // Lazy creation of font
<a name="line707"></a>      var fontSize =
<a name="line708"></a>          Math.round(r * goog.ui.Gauge.FACTOR_TITLE_FONT_SIZE);
<a name="line709"></a>      font = new goog.graphics.Font(
<a name="line710"></a>          fontSize, goog.ui.Gauge.TITLE_FONT_NAME);
<a name="line711"></a>      this.titleFont_ = font;
<a name="line712"></a>    }
<a name="line713"></a>    fill = new goog.graphics.SolidFill(theme.getTitleColor());
<a name="line714"></a>    if (this.titleTop_) {
<a name="line715"></a>      y = cy - Math.round(r * goog.ui.Gauge.FACTOR_TITLE_OFFSET);
<a name="line716"></a>      graphics.drawTextOnLine(this.titleTop_, 0, y, this.width_, y,
<a name="line717"></a>          &#39;center&#39;, font, null, fill);
<a name="line718"></a>    }
<a name="line719"></a>    if (this.titleBottom_) {
<a name="line720"></a>      y = cy + Math.round(r * goog.ui.Gauge.FACTOR_TITLE_OFFSET);
<a name="line721"></a>      graphics.drawTextOnLine(this.titleBottom_, 0, y, this.width_, y,
<a name="line722"></a>          &#39;center&#39;, font, null, fill);
<a name="line723"></a>    }
<a name="line724"></a>  }
<a name="line725"></a>
<a name="line726"></a>  // Draw tick marks
<a name="line727"></a>  var majorTicks = this.majorTicks_;
<a name="line728"></a>  var minorTicks = this.minorTicks_;
<a name="line729"></a>  var rMajorTickInternal = r * goog.ui.Gauge.FACTOR_MAJOR_TICKS;
<a name="line730"></a>  var rMinorTickInternal = r * goog.ui.Gauge.FACTOR_MINOR_TICKS;
<a name="line731"></a>  var ticks = majorTicks * minorTicks;
<a name="line732"></a>  var valueRange = this.maxValue_ - this.minValue_;
<a name="line733"></a>  var tickValueSpan = valueRange / ticks;
<a name="line734"></a>  var majorTicksPath = new goog.graphics.Path();
<a name="line735"></a>  var minorTicksPath = new goog.graphics.Path();
<a name="line736"></a>
<a name="line737"></a>  var tickLabelFill = new goog.graphics.SolidFill(theme.getTickLabelColor());
<a name="line738"></a>  var tickLabelFont = this.tickLabelFont_;
<a name="line739"></a>  if (!tickLabelFont) {
<a name="line740"></a>    tickLabelFont = new goog.graphics.Font(
<a name="line741"></a>        Math.round(r * goog.ui.Gauge.FACTOR_TICK_LABEL_FONT_SIZE),
<a name="line742"></a>        goog.ui.Gauge.TITLE_FONT_NAME);
<a name="line743"></a>  }
<a name="line744"></a>  var tickLabelFontSize = tickLabelFont.size;
<a name="line745"></a>
<a name="line746"></a>  for (var i = 0; i &lt;= ticks; i++) {
<a name="line747"></a>    var angle = this.valueToAngle_(i * tickValueSpan + this.minValue_);
<a name="line748"></a>    var isMajorTick = i % minorTicks == 0;
<a name="line749"></a>    var rInternal = isMajorTick ? rMajorTickInternal : rMinorTickInternal;
<a name="line750"></a>    var path = isMajorTick ? majorTicksPath : minorTicksPath;
<a name="line751"></a>    x = cx + goog.math.angleDx(angle, rInternal);
<a name="line752"></a>    y = cy + goog.math.angleDy(angle, rInternal);
<a name="line753"></a>    path.moveTo(x, y);
<a name="line754"></a>    x = cx + goog.math.angleDx(angle, r);
<a name="line755"></a>    y = cy + goog.math.angleDy(angle, r);
<a name="line756"></a>    path.lineTo(x, y);
<a name="line757"></a>
<a name="line758"></a>    // Draw the tick&#39;s label for major ticks
<a name="line759"></a>    if (isMajorTick &amp;&amp; this.majorTickLabels_) {
<a name="line760"></a>      var tickIndex = Math.floor(i / minorTicks);
<a name="line761"></a>      var label = this.majorTickLabels_[tickIndex];
<a name="line762"></a>      if (label) {
<a name="line763"></a>        x = cx + goog.math.angleDx(angle, rInternal - tickLabelFontSize / 2);
<a name="line764"></a>        y = cy + goog.math.angleDy(angle, rInternal - tickLabelFontSize / 2);
<a name="line765"></a>        var x1, x2;
<a name="line766"></a>        var align = &#39;center&#39;;
<a name="line767"></a>        if (angle &gt; 280 || angle &lt; 90) {
<a name="line768"></a>          align = &#39;right&#39;;
<a name="line769"></a>          x1 = 0;
<a name="line770"></a>          x2 = x;
<a name="line771"></a>        } else if (angle &gt;= 90 &amp;&amp; angle &lt; 260) {
<a name="line772"></a>          align = &#39;left&#39;;
<a name="line773"></a>          x1 = x;
<a name="line774"></a>          x2 = this.width_;
<a name="line775"></a>        } else {
<a name="line776"></a>          // Values around top (angle 260-280) are centered around point
<a name="line777"></a>          var dw = Math.min(x, this.width_ - x); // Nearest side border
<a name="line778"></a>          x1 = x - dw;
<a name="line779"></a>          x2 = x + dw;
<a name="line780"></a>          y += Math.round(tickLabelFontSize / 4); // Movea bit down
<a name="line781"></a>        }
<a name="line782"></a>        graphics.drawTextOnLine(label, x1, y, x2, y,
<a name="line783"></a>            align, tickLabelFont, null, tickLabelFill);
<a name="line784"></a>      }
<a name="line785"></a>    }
<a name="line786"></a>  }
<a name="line787"></a>  stroke = theme.getMinorTickStroke();
<a name="line788"></a>  graphics.drawPath(minorTicksPath, stroke, null);
<a name="line789"></a>  stroke = theme.getMajorTickStroke();
<a name="line790"></a>  graphics.drawPath(majorTicksPath, stroke, null);
<a name="line791"></a>
<a name="line792"></a>  // Draw the needle and the value label. Stop animation when doing
<a name="line793"></a>  // full redraw and jump to the final value position.
<a name="line794"></a>  this.stopAnimation_();
<a name="line795"></a>  this.valuePosition_ = this.valueToRangePosition_(this.value);
<a name="line796"></a>  this.needleRadius_ = r;
<a name="line797"></a>  this.drawValue_();
<a name="line798"></a>};
<a name="line799"></a>
<a name="line800"></a>
<a name="line801"></a>/**
<a name="line802"></a> * Handle animation events while the hand is moving.
<a name="line803"></a> * @param {goog.fx.AnimationEvent} e The event.
<a name="line804"></a> * @private
<a name="line805"></a> */
<a name="line806"></a>goog.ui.Gauge.prototype.onAnimate_ = function(e) {
<a name="line807"></a>  this.needleValuePosition_ = e.x;
<a name="line808"></a>  this.drawValue_();
<a name="line809"></a>};
<a name="line810"></a>
<a name="line811"></a>
<a name="line812"></a>/**
<a name="line813"></a> * Handle animation events when hand move is complete.
<a name="line814"></a> * @private
<a name="line815"></a> */
<a name="line816"></a>goog.ui.Gauge.prototype.onAnimateEnd_ = function() {
<a name="line817"></a>  this.stopAnimation_();
<a name="line818"></a>};
<a name="line819"></a>
<a name="line820"></a>
<a name="line821"></a>/**
<a name="line822"></a> * Stop the current animation, if it is active.
<a name="line823"></a> * @private
<a name="line824"></a> */
<a name="line825"></a>goog.ui.Gauge.prototype.stopAnimation_ = function() {
<a name="line826"></a>  if (this.animation_) {
<a name="line827"></a>    goog.events.removeAll(this.animation_);
<a name="line828"></a>    this.animation_.stop(false);
<a name="line829"></a>    this.animation_ = null;
<a name="line830"></a>  }
<a name="line831"></a>};
<a name="line832"></a>
<a name="line833"></a>
<a name="line834"></a>/**
<a name="line835"></a> * Convert a value to the position in the range. The returned position
<a name="line836"></a> * is a value between 0 and 1, where 0 indicates the lowest range value,
<a name="line837"></a> * 1 is the highest range, and any value in between is proportional
<a name="line838"></a> * to mapping the range to (0-1).
<a name="line839"></a> * If the value is not within the range, the returned value may be a bit
<a name="line840"></a> * lower than 0, or a bit higher than 1. This is done so that values out
<a name="line841"></a> * of range will be displayed just a bit outside of the gauge axis.
<a name="line842"></a> * @param {number} value The value to convert.
<a name="line843"></a> * @private
<a name="line844"></a> * @return {number} The range position.
<a name="line845"></a> */
<a name="line846"></a>goog.ui.Gauge.prototype.valueToRangePosition_ = function(value) {
<a name="line847"></a>  var valueRange = this.maxValue_ - this.minValue_;
<a name="line848"></a>  var valuePct = (value - this.minValue_) / valueRange; // 0 to 1
<a name="line849"></a>
<a name="line850"></a>  // If value is out of range, trim it not to be too much out of range
<a name="line851"></a>  valuePct = Math.max(valuePct,
<a name="line852"></a>      -goog.ui.Gauge.MAX_EXCEED_POSITION_POSITION);
<a name="line853"></a>  valuePct = Math.min(valuePct,
<a name="line854"></a>      1 + goog.ui.Gauge.MAX_EXCEED_POSITION_POSITION);
<a name="line855"></a>
<a name="line856"></a>  return valuePct;
<a name="line857"></a>};
<a name="line858"></a>
<a name="line859"></a>
<a name="line860"></a>/**
<a name="line861"></a> * Convert a value to an angle based on the value range and angle span
<a name="line862"></a> * @param {number} value The value.
<a name="line863"></a> * @return {number} The angle where this value is located on the round
<a name="line864"></a> *     axis, based on the range and angle span.
<a name="line865"></a> * @private
<a name="line866"></a> */
<a name="line867"></a>goog.ui.Gauge.prototype.valueToAngle_ = function(value) {
<a name="line868"></a>  var valuePct = this.valueToRangePosition_(value);
<a name="line869"></a>  return this.valuePositionToAngle_(valuePct);
<a name="line870"></a>};
<a name="line871"></a>
<a name="line872"></a>
<a name="line873"></a>/**
<a name="line874"></a> * Convert a value-position (percent in the range) to an angle based on
<a name="line875"></a> * the angle span. A value-position is a value that has been proportinally
<a name="line876"></a> * adjusted to a value betwwen 0-1, proportionaly to the range.
<a name="line877"></a> * @param {number} valuePct The value.
<a name="line878"></a> * @return {number} The angle where this value is located on the round
<a name="line879"></a> *     axis, based on the range and angle span.
<a name="line880"></a> * @private
<a name="line881"></a> */
<a name="line882"></a>goog.ui.Gauge.prototype.valuePositionToAngle_ = function(valuePct) {
<a name="line883"></a>  var startAngle = goog.math.standardAngle((360 - this.angleSpan_) / 2 + 90);
<a name="line884"></a>  return this.angleSpan_ * valuePct + startAngle;
<a name="line885"></a>};
<a name="line886"></a>
<a name="line887"></a>
<a name="line888"></a>/**
<a name="line889"></a> * Draw the elements that depend on the current value (the needle and
<a name="line890"></a> * the formatted value). This function is called whenever a value is changed
<a name="line891"></a> * or when the entire gauge is redrawn.
<a name="line892"></a> * @private
<a name="line893"></a> */
<a name="line894"></a>goog.ui.Gauge.prototype.drawValue_ = function() {
<a name="line895"></a>  if (!this.isInDocument()) {
<a name="line896"></a>    return;
<a name="line897"></a>  }
<a name="line898"></a>
<a name="line899"></a>  var r = this.needleRadius_;
<a name="line900"></a>  var graphics = this.graphics_;
<a name="line901"></a>  var theme = this.theme_;
<a name="line902"></a>  var cx = this.width_ / 2;
<a name="line903"></a>  var cy = this.height_ / 2;
<a name="line904"></a>  var angle = this.valuePositionToAngle_(
<a name="line905"></a>      /** @type {number} */(this.needleValuePosition_));
<a name="line906"></a>
<a name="line907"></a>  // Compute the needle path
<a name="line908"></a>  var frontRadius =
<a name="line909"></a>      Math.round(r * goog.ui.Gauge.FACTOR_NEEDLE_FRONT);
<a name="line910"></a>  var backRadius =
<a name="line911"></a>      Math.round(r * goog.ui.Gauge.FACTOR_NEEDLE_BACK);
<a name="line912"></a>  var frontDx = goog.math.angleDx(angle, frontRadius);
<a name="line913"></a>  var frontDy = goog.math.angleDy(angle, frontRadius);
<a name="line914"></a>  var backDx = goog.math.angleDx(angle, backRadius);
<a name="line915"></a>  var backDy = goog.math.angleDy(angle, backRadius);
<a name="line916"></a>  var angleRight = goog.math.standardAngle(angle + 90);
<a name="line917"></a>  var distanceControlPointBase = r * goog.ui.Gauge.FACTOR_NEEDLE_WIDTH;
<a name="line918"></a>  var controlPointMidDx = goog.math.angleDx(angleRight,
<a name="line919"></a>      distanceControlPointBase);
<a name="line920"></a>  var controlPointMidDy = goog.math.angleDy(angleRight,
<a name="line921"></a>      distanceControlPointBase);
<a name="line922"></a>
<a name="line923"></a>  var path = new goog.graphics.Path();
<a name="line924"></a>  path.moveTo(cx + frontDx, cy + frontDy);
<a name="line925"></a>  path.curveTo(cx + controlPointMidDx, cy + controlPointMidDy,
<a name="line926"></a>      cx - backDx + (controlPointMidDx / 2),
<a name="line927"></a>      cy - backDy + (controlPointMidDy / 2),
<a name="line928"></a>      cx - backDx, cy - backDy);
<a name="line929"></a>  path.curveTo(cx - backDx - (controlPointMidDx / 2),
<a name="line930"></a>      cy - backDy - (controlPointMidDy / 2),
<a name="line931"></a>      cx - controlPointMidDx, cy - controlPointMidDy,
<a name="line932"></a>      cx + frontDx, cy + frontDy);
<a name="line933"></a>
<a name="line934"></a>  // Draw the needle hinge
<a name="line935"></a>  var rh = Math.round(r * goog.ui.Gauge.FACTOR_NEEDLE_HINGE);
<a name="line936"></a>
<a name="line937"></a>  // Clean previous needle
<a name="line938"></a>  var needleGroup = this.needleGroup_;
<a name="line939"></a>  if (needleGroup) {
<a name="line940"></a>    needleGroup.clear();
<a name="line941"></a>  } else {
<a name="line942"></a>    needleGroup = this.needleGroup_ = graphics.createGroup();
<a name="line943"></a>  }
<a name="line944"></a>
<a name="line945"></a>  // Draw current formatted value if provided.
<a name="line946"></a>  if (this.formattedValue_) {
<a name="line947"></a>    var font = this.valueFont_;
<a name="line948"></a>    if (!font) {
<a name="line949"></a>      var fontSize =
<a name="line950"></a>          Math.round(r * goog.ui.Gauge.FACTOR_VALUE_FONT_SIZE);
<a name="line951"></a>      font = new goog.graphics.Font(fontSize,
<a name="line952"></a>          goog.ui.Gauge.TITLE_FONT_NAME);
<a name="line953"></a>      font.bold = true;
<a name="line954"></a>      this.valueFont_ = font;
<a name="line955"></a>    }
<a name="line956"></a>    var fill = new goog.graphics.SolidFill(theme.getValueColor());
<a name="line957"></a>    var y = cy + Math.round(r * goog.ui.Gauge.FACTOR_VALUE_OFFSET);
<a name="line958"></a>    graphics.drawTextOnLine(this.formattedValue_, 0, y, this.width_, y,
<a name="line959"></a>        &#39;center&#39;, font, null, fill, needleGroup);
<a name="line960"></a>  }
<a name="line961"></a>
<a name="line962"></a>  // Draw the needle
<a name="line963"></a>  var stroke = theme.getNeedleStroke();
<a name="line964"></a>  var fill = theme.getNeedleFill(cx, cy, rh);
<a name="line965"></a>  graphics.drawPath(path, stroke, fill, needleGroup);
<a name="line966"></a>  stroke = theme.getHingeStroke();
<a name="line967"></a>  fill = theme.getHingeFill(cx, cy, rh);
<a name="line968"></a>  graphics.drawCircle(cx, cy, rh, stroke, fill, needleGroup);
<a name="line969"></a>};
<a name="line970"></a>
<a name="line971"></a>
<a name="line972"></a>/**
<a name="line973"></a> * Redraws the entire gauge.
<a name="line974"></a> * Should be called after theme colors have been changed.
<a name="line975"></a> */
<a name="line976"></a>goog.ui.Gauge.prototype.redraw = function() {
<a name="line977"></a>  this.draw_();
<a name="line978"></a>};
<a name="line979"></a>
<a name="line980"></a>
<a name="line981"></a>/** @override */
<a name="line982"></a>goog.ui.Gauge.prototype.enterDocument = function() {
<a name="line983"></a>  goog.ui.Gauge.superClass_.enterDocument.call(this);
<a name="line984"></a>
<a name="line985"></a>  // set roles and states
<a name="line986"></a>  var el = this.getElement();
<a name="line987"></a>  goog.asserts.assert(el, &#39;The DOM element for the gauge cannot be null.&#39;);
<a name="line988"></a>  goog.a11y.aria.setRole(el, &#39;progressbar&#39;);
<a name="line989"></a>  goog.a11y.aria.setState(el, &#39;live&#39;, &#39;polite&#39;);
<a name="line990"></a>  goog.a11y.aria.setState(el, &#39;valuemin&#39;, this.minValue_);
<a name="line991"></a>  goog.a11y.aria.setState(el, &#39;valuemax&#39;, this.maxValue_);
<a name="line992"></a>  goog.a11y.aria.setState(el, &#39;valuenow&#39;, this.value_);
<a name="line993"></a>  this.draw_();
<a name="line994"></a>};
<a name="line995"></a>
<a name="line996"></a>
<a name="line997"></a>/** @override */
<a name="line998"></a>goog.ui.Gauge.prototype.exitDocument = function() {
<a name="line999"></a>  goog.ui.Gauge.superClass_.exitDocument.call(this);
<a name="line1000"></a>  this.stopAnimation_();
<a name="line1001"></a>};
<a name="line1002"></a>
<a name="line1003"></a>
<a name="line1004"></a>/** @override */
<a name="line1005"></a>goog.ui.Gauge.prototype.disposeInternal = function() {
<a name="line1006"></a>  this.stopAnimation_();
<a name="line1007"></a>  this.graphics_.dispose();
<a name="line1008"></a>  delete this.graphics_;
<a name="line1009"></a>  delete this.needleGroup_;
<a name="line1010"></a>  delete this.theme_;
<a name="line1011"></a>  delete this.rangeColors_;
<a name="line1012"></a>  goog.ui.Gauge.superClass_.disposeInternal.call(this);
<a name="line1013"></a>};
</pre>


</body>
</html>
